﻿using System;
using System.Data;
using System.Collections;
using CE.Database;

/// <summary>
/// Summary description for LibertyCarMoreDetailDB
/// </summary>
/// 
namespace CE.CarInsurance
{
    public class LibertyCarMoreDetailDB
    {
        public LibertyCarMoreDetailDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(LibertyCarMoreDetail libertycarmoredetail)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCarMoreDetailInsertUpdateSingleItemLiberty";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CECarMoreDetailId", libertycarmoredetail.CECarMoreDetailId);
            _sPara.Add("@CECarID", libertycarmoredetail.CECarId);
            _sPara.Add("@ProviderCompanyId", libertycarmoredetail.ProviderCompanyId);
            _sPara.Add("@Name", libertycarmoredetail.Name);
            _sPara.Add("@PostalCode", libertycarmoredetail.PostalCode);
            _sPara.Add("@UnitNo", libertycarmoredetail.UnitNo);
            _sPara.Add("@HomeNo", libertycarmoredetail.HomeNo);
            _sPara.Add("@Address", libertycarmoredetail.Address);
            _sPara.Add("@MobileNo", libertycarmoredetail.MobileNo);
            _sPara.Add("@HomePhoneNo", libertycarmoredetail.HomePhoneNo);
            _sPara.Add("@OfficePhoneNo", libertycarmoredetail.OfficePhoneNo);
            _sPara.Add("@NRICNo", libertycarmoredetail.NRICNo);
            _sPara.Add("@Nationality", libertycarmoredetail.Nationality);
            _sPara.Add("@EmpNameandTrade", libertycarmoredetail.EmpNameandTrade);
            _sPara.Add("@HasDriveWestMalaysia", libertycarmoredetail.HasDriveWestMalaysia);
            _sPara.Add("@NCDReason", libertycarmoredetail.NCDReason);
            _sPara.Add("@NCDOtherReason", libertycarmoredetail.NCDOtherReason);
            _sPara.Add("@VechicleNo", libertycarmoredetail.VechicleNo);
            //_sPara.Add("@OdometerReading", libertycarmoredetail.OdometerReading);
            _sPara.Add("@DateofRegistration", libertycarmoredetail.DateofRegistration);
            _sPara.Add("@EngineNo", libertycarmoredetail.EngineNo);
            _sPara.Add("@ChassisNo", libertycarmoredetail.ChassisNo);
            //_sPara.Add("@EstimateMarketValue", libertycarmoredetail.EstimateMarketValue);
            _sPara.Add("@HasHirePurchase", libertycarmoredetail.HasHirePurchase);
            _sPara.Add("@HPCompanyName", libertycarmoredetail.HPCompanyName);
            //_sPara.Add("@HPCPostalCode", libertycarmoredetail.HPCPostalCode);
            //_sPara.Add("@HPCUnitNo", libertycarmoredetail.HPCUnitNo);
            //_sPara.Add("@HPCHomeNo", libertycarmoredetail.HPCHomeNo);
            //_sPara.Add("@HPCAddress", libertycarmoredetail.HPCAddress);
            _sPara.Add("@HasPreInsurer", libertycarmoredetail.HasPreInsurer);
            _sPara.Add("@PreInsurerName", libertycarmoredetail.PreInsurerName);
            _sPara.Add("@PreInsVechicleNo", libertycarmoredetail.PreInsVechicleNo);
            //_sPara.Add("@PreInsPolicyNo", libertycarmoredetail.PreInsPolicyNo);
            _sPara.Add("@PreInsExpiryDate", libertycarmoredetail.PreInsExpiryDate);
            _sPara.Add("@NCDEntitlement", libertycarmoredetail.NCDEntitlement);
            _sPara.Add("@HasVechicleModified", libertycarmoredetail.HasVechicleModified);
            _sPara.Add("@VechicleModifyReason", libertycarmoredetail.VechicleModifyReason);
            _sPara.Add("@HasAccessory", libertycarmoredetail.HasAccessory);
            _sPara.Add("@AccessoryDescription", libertycarmoredetail.AccessoryDescription);
            //_sPara.Add("@InsuranceFromDate", libertycarmoredetail.InsuranceFromDate);
            //_sPara.Add("@InsuranceToDate", libertycarmoredetail.InsuranceToDate);
            _sPara.Add("@HasConvictedMoterOffence", libertycarmoredetail.HasConvictedMoterOffence);
            _sPara.Add("@ConvictedReason", libertycarmoredetail.ConvictedReason);
            _sPara.Add("@HasDemeritPoints", libertycarmoredetail.HasDemeritPoints);
            _sPara.Add("@HasPhysicalImpairment", libertycarmoredetail.HasPhysicalImpairment);
            _sPara.Add("@PhysicalImpairmentReason", libertycarmoredetail.PhysicalImpairmentReason);
            _sPara.Add("@HasInsuranceTerminated", libertycarmoredetail.HasInsuranceTerminated);
            _sPara.Add("@InsuranceTerminatedReason", libertycarmoredetail.InsuranceTerminatedReason);
            _sPara.Add("@PamentType", libertycarmoredetail.PamentType);        
            _sPara.Add("@QuoteRefNo", libertycarmoredetail.QuoteRefNo);
            _sPara.Add("@RefCEUserId", libertycarmoredetail.RefCEUserId);
            _sPara.Add("@ViewedDetailId", libertycarmoredetail.ViewedDetailId);
            _sPara.Add("@Status", libertycarmoredetail.Status);
            _sPara.Add("@CarResultId", libertycarmoredetail.CarResultId);
            _sPara.Add("@Info1", libertycarmoredetail.Info1);
            _sPara.Add("@Info2", libertycarmoredetail.Info2);
            _sPara.Add("@Info3", libertycarmoredetail.Info3);
            _sPara.Add("@NInfo1", libertycarmoredetail.NInfo1);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public Int64 UpdateStatus(LibertyCarMoreDetail libertycarmoredetail)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCISelectedItemStatusUpdateSingleItemLiberty";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CECarID", libertycarmoredetail.CECarId);
            _sPara.Add("@CarResultId", libertycarmoredetail.CarResultId);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        public LibertyCarMoreDetail GetCarMoreDetail(Int64 CarId, Int64 CEUserId)
        {
            LibertyCarMoreDetail _libertycarmoredetail = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarMoreDetailSelectSingleItemLiberty";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarID", CarId);
            _spara.Add("@RefCEUserId", CEUserId);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);
            if (_dt != null)
            {
                if (_dt.Rows.Count > 0)
                {
                    _libertycarmoredetail = new LibertyCarMoreDetail();
                    _libertycarmoredetail = FillDataRecord(_dt);
                }
            }
            return _libertycarmoredetail;
        }

        private LibertyCarMoreDetail FillDataRecord(DataTable myDataTable)
        {
            LibertyCarMoreDetail myCarMoreDetail = new LibertyCarMoreDetail();
            myCarMoreDetail.CECarMoreDetailId = Convert.ToInt64(myDataTable.Rows[0]["CECarMoreDetailId"].ToString());
            myCarMoreDetail.CECarId = Convert.ToInt64(myDataTable.Rows[0]["CECarID"].ToString());
            myCarMoreDetail.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[0]["ProviderCompanyId"].ToString());
            myCarMoreDetail.Name = myDataTable.Rows[0]["Name"].ToString();
            myCarMoreDetail.PostalCode = myDataTable.Rows[0]["PostalCode"].ToString();
            myCarMoreDetail.UnitNo = myDataTable.Rows[0]["UnitNo"].ToString();
            myCarMoreDetail.HomeNo = myDataTable.Rows[0]["HomeNo"].ToString();
            myCarMoreDetail.Address = myDataTable.Rows[0]["Address"].ToString();
            myCarMoreDetail.EmpNameandTrade = myDataTable.Rows[0]["EmpNameandTrade"].ToString();
            myCarMoreDetail.MobileNo = myDataTable.Rows[0]["MobileNo"].ToString();
            myCarMoreDetail.HomePhoneNo = myDataTable.Rows[0]["HomePhoneNo"].ToString();
            myCarMoreDetail.OfficePhoneNo = myDataTable.Rows[0]["OfficePhoneNo"].ToString();
            myCarMoreDetail.NRICNo = myDataTable.Rows[0]["NRICNo"].ToString();
            myCarMoreDetail.Nationality = myDataTable.Rows[0]["Nationality"].ToString();
            myCarMoreDetail.HasDriveWestMalaysia = myDataTable.Rows[0]["HasDriveWestMalaysia"].ToString();
            myCarMoreDetail.NCDReason = myDataTable.Rows[0]["NCDReason"].ToString();
            myCarMoreDetail.NCDOtherReason = myDataTable.Rows[0]["NCDOtherReason"].ToString();
            myCarMoreDetail.VechicleNo = myDataTable.Rows[0]["VechicleNo"].ToString();
            //myCarMoreDetail.OdometerReading = myDataTable.Rows[0]["OdometerReading"].ToString();
            myCarMoreDetail.DateofRegistration = Convert.ToDateTime(myDataTable.Rows[0]["DateofRegistration"].ToString());
            myCarMoreDetail.EngineNo = myDataTable.Rows[0]["EngineNo"].ToString();
            myCarMoreDetail.ChassisNo = myDataTable.Rows[0]["ChassisNo"].ToString();
            //myCarMoreDetail.EstimateMarketValue = Convert.ToSingle(myDataTable.Rows[0]["EstimateMarketValue"].ToString());
            myCarMoreDetail.HasHirePurchase = Convert.ToBoolean(myDataTable.Rows[0]["HasHirePurchase"].ToString());
            myCarMoreDetail.HPCompanyName = myDataTable.Rows[0]["HPCompanyName"].ToString();
            //myCarMoreDetail.HPCPostalCode = myDataTable.Rows[0]["HPCPostalCode"].ToString();
            //myCarMoreDetail.HPCUnitNo = myDataTable.Rows[0]["HPCUnitNo"].ToString();
            //myCarMoreDetail.HPCHomeNo = myDataTable.Rows[0]["HPCHomeNo"].ToString();
            //myCarMoreDetail.HPCAddress = myDataTable.Rows[0]["HPCAddress"].ToString();
            myCarMoreDetail.HasPreInsurer = Convert.ToBoolean(myDataTable.Rows[0]["HasPreInsurer"].ToString());
            myCarMoreDetail.PreInsurerName = myDataTable.Rows[0]["PreInsurerName"].ToString();
            myCarMoreDetail.PreInsVechicleNo = myDataTable.Rows[0]["PreInsVechicleNo"].ToString();
            //myCarMoreDetail.PreInsPolicyNo = myDataTable.Rows[0]["PreInsPolicyNo"].ToString();
            myCarMoreDetail.PreInsExpiryDate = Convert.ToDateTime(myDataTable.Rows[0]["PreInsExpiryDate"].ToString());
            myCarMoreDetail.NCDEntitlement = myDataTable.Rows[0]["NCDEntitlement"].ToString();
            myCarMoreDetail.HasVechicleModified = Convert.ToBoolean(myDataTable.Rows[0]["HasVechicleModified"].ToString());
            myCarMoreDetail.VechicleModifyReason = myDataTable.Rows[0]["VechicleModifyReason"].ToString();
            myCarMoreDetail.HasAccessory = Convert.ToBoolean(myDataTable.Rows[0]["HasAccessory"].ToString());
            myCarMoreDetail.AccessoryDescription = myDataTable.Rows[0]["AccessoryDescription"].ToString();
            //myCarMoreDetail.InsuranceFromDate = Convert.ToDateTime(myDataTable.Rows[0]["InsuranceFromDate"].ToString());
            //myCarMoreDetail.InsuranceToDate = Convert.ToDateTime(myDataTable.Rows[0]["InsuranceToDate"].ToString());
            myCarMoreDetail.HasConvictedMoterOffence = Convert.ToBoolean(myDataTable.Rows[0]["HasConvictedMoterOffence"].ToString());
            myCarMoreDetail.ConvictedReason = myDataTable.Rows[0]["ConvictedReason"].ToString();
            myCarMoreDetail.HasDemeritPoints = Convert.ToBoolean(myDataTable.Rows[0]["HasDemeritPoints"].ToString());
            myCarMoreDetail.HasPhysicalImpairment = Convert.ToBoolean(myDataTable.Rows[0]["HasPhysicalImpairment"].ToString());
            myCarMoreDetail.PhysicalImpairmentReason = myDataTable.Rows[0]["PhysicalImpairmentReason"].ToString();
            myCarMoreDetail.HasInsuranceTerminated = Convert.ToBoolean(myDataTable.Rows[0]["HasInsuranceTerminated"].ToString());
            myCarMoreDetail.InsuranceTerminatedReason = myDataTable.Rows[0]["InsuranceTerminatedReason"].ToString();
            myCarMoreDetail.RowGUID = myDataTable.Rows[0]["RowGUID"].ToString();
            myCarMoreDetail.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
            myCarMoreDetail.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());

            if (myDataTable.Rows[0]["Info1"].ToString() != "")
                myCarMoreDetail.Info1 = myDataTable.Rows[0]["Info1"].ToString();
            else
                myCarMoreDetail.Info1 = "0";

            if (myDataTable.Rows[0]["Info2"].ToString() != "")
                myCarMoreDetail.Info2 = myDataTable.Rows[0]["Info2"].ToString();
            else
                myCarMoreDetail.Info2 = "0";

            return myCarMoreDetail;
        }

        public DataSet GetCarPolicyDetails(Int64 CarId, Int64 CEId, Int64 CXCoverTypeId, Int64 ProviderCompanyId)
        {
            DataSet _result = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarInsuranceSelectedPlanSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarId", CarId);
            _spara.Add("@RefCEUserId", CEId);
            _spara.Add("@CITempResultId", CXCoverTypeId);
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);


            using (DataSet _ds = _db.GetDataSet(_spName, _spara))
            {
                if (_ds != null && _ds.Tables[0].Rows.Count > 0)
                {
                    _result = _ds;
                }
            }
            return _result;
        }

    }
}